package com.petter.gradlespringboot.controller;

import com.petter.gradlespringboot.entity.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.support.RequestContextUtils;

import javax.servlet.http.HttpServletRequest;

/**
 * @author : GD
 * @date :2021/4/27 : 9:14
 */
@RestController
@RequestMapping("test")
public class IndexController {

    @RequestMapping("index")
    @ResponseBody
    public String index(HttpServletRequest request){
        //springMVC上下文
        WebApplicationContext context = RequestContextUtils.findWebApplicationContext(request);
        User user = (User) context.getBean("user");
        Object aopTest = context.getBean("AOPTest");
        System.out.println(aopTest);
        return user.toString()  + System.currentTimeMillis();
    }

}
